package net.obxlabs.tweetpad.behaviour;

import net.nexttext.*;
import net.nexttext.behaviour.physics.*;
import net.nexttext.property.*;
import processing.core.*;

/**
 * Drags n shit
 *
 * $Id:MouseInertia.java 16 2007-11-27 10:50:46Z prisonerjohn $
 */
public class MouseInertia extends PhysicsAction {
	private PApplet p;
	private float scale;
	
	public MouseInertia(PApplet p, int mouseButton, float scale) {
    	this.p = p;
    	this.scale = scale;
    }
    
    public ActionResult behave(TextObject to) {
    	BooleanProperty dragging = (BooleanProperty)to.getProperty("Dragging");
    	if (dragging != null) {
    		if (dragging.get()) {
        		// TextObject was being dragged at the last frame, add inertia
    			Vector3 inertia = new Vector3(p.mouseX-p.pmouseX, p.mouseY-p.pmouseY);
    			inertia.scalar(scale);
    			
    			applyForce(to, inertia);
    			
        		dragging.set(false);
        	}
        }
    	
        return new ActionResult(false, false, false);
    }
}
